package NC96_判断一个链表是否为回文结构;

import java.util.*;

class ListNode {
    int val;
    ListNode next = null;
}

public class Solution {
    /**
     *
     * @param head ListNode类 the head
     * @return bool布尔型
     */
    public boolean isPail (ListNode head) {
        // write code here
        if (head.next == null){
            return true;
        }
        List<Integer> list = new ArrayList<>();
        while (head != null){
            list.add(head.val);
            head = head.next;
        }
        int i = 0;
        int j = list.size() - 1;
        while (i < j){
            if (!list.get(i).equals(list.get(j))){
                return false;
            }
            i++;
            j--;
        }
        return true;

    }
}